#ifndef _SSD1306_H
#define _SSD1306_H

#include "main.h"
#include "math.h"

#define OLED_CHIP_ADDR 0x78
#define OLED_CHIP_TIMEOUT 100

#define OLED_OPEN_DISPLAY 0xaf                //开屏幕显示
#define OLED_CLOSE_DISPLAY 0xae               //关屏幕显示
#define OLED_SET_CONTRAST_RATIO 0x81          //设置对比度
#define OLED_SET_ADDR_SEEKING_MODE 0x20       //设置地址模式

#define OLED_ADDR_SEEKING_MODE_VERTICAL 0x1   //垂直地址模式
#define OLED_ADDR_SEEKING_MODE_HORIZONTAL 0x0 //水平地址模式
#define OLED_ADDR_SEEKING_MODE_PAGE 0x2       //页地址模式

#define OLED_SET_CLKDIV 0xd5                  //设置时钟分频因子，跟一字节参数。参数[3:0]为分频因子，[7:4]为震荡频率
#define OLED_SET_DEVCHANNELS 0xa8             //设置驱动路数
#define OLED_SET_DISPLAY_OFFSET 0xd3          //设置显示偏移
#define OLED_SET_DIS_START 0x40               //设置显示开始行。[5:0]为行数.

#define GRAM_SIZE 1024

HAL_StatusTypeDef SSD1306_send_cmd (I2C_HandleTypeDef *hi2c, unsigned char cmd);
HAL_StatusTypeDef SSD1306_send_data (I2C_HandleTypeDef *hi2c, unsigned char *data, unsigned int data_size);
int SSD1306_Clean ();
HAL_StatusTypeDef SSD1306_Init (I2C_HandleTypeDef *hi2c);
int SSD1306_ChangeMapping (unsigned char *mapping_array);

HAL_StatusTypeDef SSD1306_UpdateDisplay (I2C_HandleTypeDef *hi2c);

int SSD1306_WritePoint (int x, int y);
int SSD1306_DrawJX (int x1, int y1, int x2, int y2);
int SSD1306_DrawZX (int x1, int y1, int x2, int y2);
int SSD1306_DrawFZ (int xb, int yb, unsigned char *fz);

#endif
